/**
 * Created by Administrator on 2018/11/2 0002.
 */
var model_phone='';
//用户信息替换
function user_info_tihuan() {
    layui.use(['layer'], function() {
        var index = layer.load(2, {shade: [0.1,'#fff'],time: 60*1000});
        var id = $('#info_id').val();
        var html ='';
        sign.params={
            id:id
        };
        var encode_data = sign.encode_post();
        $.post(url_list.user_info,encode_data,function (data) {
            //解码
            if(typeof data == 'string'){
                data = JSON.parse(data);
            }
            data = sign.decode_post(data);

            if (data.code == 200) {
                model_phone=data.data.phone;
                html +=
                '<li>'+
                '<label class="res-lab">定期修改密码</label>' +
                '<a href="#" onclick="update_account_info()" style="margin-left: 300px;color: #00b3ee" id="r_name">修改密码</a>'+
                '</li>'+
                '<li>'+
                '<label class="res-lab">改绑手机号码</label>' +
                '<a href="#" onclick="no_page()" style="margin-left: 300px;color: #00b3ee"  id="r_phone">'+data.data.phone+'</a>'+
                '</li>'+
                '<li>'+
                '<label class="res-lab">改绑邮箱地址</label>' +
                '<a href="#" onclick="no_page()" style="margin-left: 300px;color: #00b3ee"  id="r_email">'+data.data.email+'</a>'+
                '</li>'+
                '<li>'+
                '<label class="res-lab">登陆日志</label>' +
                '<a href="#" onclick="no_page()" style="margin-left: 300px;color: #00b3ee"  id="r_intro">查看</a>'+
                '</li>';
                $('#sys-info-list').html(html);
            } else {
                layer.msg(data.msg, {icon: 2});
            }layer.close(index);
        })
    });

}

//修改密码弹出层，打开修改密码弹窗
function update_account_info() {
    $('.bgPop,.pop').show();
}
//关闭修改密码弹窗
function update_account_info_outcli() {
    $('.bgPop,.pop').hide();
}

// 改绑手机号的弹窗，获取弹窗
var modal = document.getElementById('myModal');
// 打开弹窗的按钮对象
var btn = document.getElementById("myBtn");
// 获取 <span> 元素，用于关闭弹窗
var span = document.querySelector('.close');
//修改头像
function update_img() {
    modal.style.display = "block";
}
// 点击 <span> (x), 关闭弹窗
function update_img_close() {
    modal.style.display = "none";
};
// 在用户点击其他地方时，关闭弹窗
window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }
};

//修改密码
function pass_update() {
    var oldpwd = $('#oldpwd').val(),
        newpwd = $('#newpwd').val(),
        newpwd_confirm = $('#newpwd_confirm').val();
    sign.params={
        oldpwd:oldpwd,
        newpwd:newpwd,
        newpwd_confirm:newpwd_confirm
    };
    var encode_data = sign.encode_post();
    $.post(url_list.user_update_info,encode_data,function (data) {
        //解码
        if(typeof data == 'string'){
            data = JSON.parse(data);
        }
        data = sign.decode_post(data);
        layui.use(['layer'], function() {
            if (data.code == 200) {
                layer.msg('修改成功，请重新登录', {icon: 1, time: 3000});
                logout();
            } else {
                layer.msg(data.msg, {icon: 2});
            }
        })
    });
}
